package ModelLag;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * The DVD class creates an object of the type DVD.
 * 
 * @author (Lackshan, Mikkel, Nick, patrick, Simon, Yousef) 
 * @project (Tema design)
 * @version (2014.11.04)
 */
public class DVD
{
    private ArrayList<Copy> copys;
    private String barcode, title, artist, publicationDate;
    
    /**
     * Constructor for objects of class DVD
     * 
     * @param b is the user input for the barcide of a DVD.
     * @param t is the user input for the title of a DVD.
     * @param a is the user input for the artist of a DVD.
     * @param p is the user input for the publicationDate of a DVD.
     */
    
    public DVD(String b, String t, String a, String p){
        copys = new ArrayList<Copy>();
        barcode = b;
        title = t;
        artist = a;
        publicationDate = p;
    }
     
    
    /**
     * Sets the title for the DVD.
     * 
     * @param t is the user input for the title of a DVD.
     */
    public void setTitle(String title){
        this.title = title;
    }
    
    /**
     * Sets the artist for the DVD.
     * 
     * @param a is the user input for the artist of a DVD.
     */
    public void setArtist(String artist){
        this.artist = artist;
    }
    
    /**
     * Sets the publication date for the DVD.
     * 
     * @param p is the user input for the publication date of a DVD.
     */
    public void setPublicationDate(String publicationDate){
        this.publicationDate = publicationDate;
    }
    
    /**
     * Returns the barcode for the DVD.
     * 
     * @param returns the barcode of the DVD
     */
    public String getBarcode(){
        return barcode;
    }
    
    /**
     * Returns the title for the DVD.
     * 
     * @param returns the title of the DVD
     */
    public String getTitle(){
        return title;
    }
    
    /**
     * Returns the artist for the DVD.
     * 
     * @param returns the artist of the DVD
     */
    public String getArtist(){
        return artist;
    }
    
    /**
     * Returns the publication date for the DVD.
     * 
     * @param returns the publication date of the DVD
     */
    public String getPublicationDate(){
        return publicationDate;
    }
    
    /**
     * Adds a copy to the DVD´s collection
     * 
     * @param copy the copy to be added
     */
    public void addCopy(Copy copy){
        copys.add(copy);
    }
    /**
     * Returns a true if the DVD contains a copy with the given serial number
     * 
     * @param serialNumber the serial number of the copy
     */
    public boolean containsCopy(String serialNumber){
        boolean found = false;
        int i = 0;
        while(!found && i<copys.size()){
            Copy copy = copys.get(i);
            if(serialNumber.equals(copy.getSerialNumber())){
                found = true; 
                return true;
            }
            i++;   
        }
        return false;
    }
    
    /**
     * Returns the DVD´s copys
     * 
     * @return ArrayList<Copy> of copys
     */
    public Copy findCopy(String serialNumber){
        boolean found = false;
        int i = 0;
        while(!found && i<copys.size()){
            Copy copy = copys.get(i);
            if(serialNumber.equals(copy.getSerialNumber())){
                found = true;
                return copy;
            }
            i++;
        }
        return null;
    }
    
    /**
     * Delete a copy from the collection
     * 
     * @param serialNumber the serial number of the copy
     */
    public void deleteCopy(String serialNumber){
        Iterator<Copy> it = copys.iterator();
        while(it.hasNext()){
            Copy c = it.next();
            if(c.getSerialNumber().equals(serialNumber)){
                it.remove();
            }
        }
    }
}
